
function requetData() {
    $.ajax({
        url:"/friendlist/showallfriends" ,
        dataType:"json",
        type:"get",
        success:function (data) {
            console.log(data)
            showData(data)
        }
    })
}

// 删除好友
function deletefriend(userId) {
    console.log(userId)
    $.ajax({
        url: "/friendlist/deletefriend",
        data: "friendUserId=" + userId,
        //dataType: "json",
        type: "post",
        success: function (data) {
            if (data == "success") {
                alert("删除成功")
                setTimeout(function () {
                    location.href = "/friendlist.jsp"
                }, 1000)
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            alert(XMLHttpRequest.readyState + XMLHttpRequest.status + XMLHttpRequest.responseText);
        }
    })
}
function sendgame(friendUserId) {
document.location.href="/gamelist.html?friendUserId="+friendUserId;
}
function chat(friendUserId,userName) {

    window.location.href="/chat.jsp?friendUserId="+friendUserId
}

function  showData(jsonObj) {

    var html = ' <tr><th>用户名</th><th></th><th></th><th></th></tr>'


    for(var i = 0; i < jsonObj.length; i ++) {
        html = html + "<tr><td>"
        html = html + jsonObj[i].userName
        html = html + "</td><td>"
        html = html + "<button  class='btnv6_blue_hoverfade  btn btn-primary btn-sm' onclick='deletefriend(" + jsonObj[i].friendUserId + ")'>删除</button>"
        html = html + "</td><td>"
        html = html + "<button  class='btnv6_blue_hoverfade  btn btn-primary btn-sm' onclick='chat(" +jsonObj[i].friendUserId+");'>聊天</button>"
        html = html + "</td>"
        html = html + "<td><button  class='btnv6_blue_hoverfade  btn btn-primary btn-sm'onclick='sendgame(" + jsonObj[i].friendUserId + ")'>赠送礼物</button></td>"
        html = html + "</tr>"
        

        }
        




    $('.table').html(html)

}
requetData();
